import { action, makeObservable, observable } from "mobx";
import { createContext, useContext } from "react";
import TodoViewStore from "./TodoViewStore";

class TodoListStore {
    todos = []
    constructor(todos) {
        if (todos) this.todos = todos
        makeObservable(this,{
            todos:observable,
            createTitle:action.bound,
        })
    }
    createTitle(title) {
        console.log(title)
        this.todos.push(new TodoViewStore( title ))
    }
    // createId() {
    //     if (!this.todos.length) return 1
    //     return this.todos.reduce((id, todo) => id < todo.id ? todo.id : id, 0) + 1
    // }
}
const TodoListContent = createContext()
const TodoListStoreProvider = ({store,children})=>{
    <TodoListContent.Provider value={store}>
        {children}
    </TodoListContent.Provider>
}
const useTodoListStore = ()=>{
    return useContext(TodoListContent)
}
export default TodoListStore;